package tvdi

class Usuario {
	
    String login
    String password
	String role = "user"
	
    static constraints = {
		login(blank:false, nullable:false, unique:true)
		role(inList:['admin', 'user'])
		password(blank:false, password:true)
    }
    
    static transients = ['admin']
    
    boolean isAdmin(){
		return role == "admin"
    }
    
    def beforeInsert = {
		password = password.encodeAsSHA()
    }
    
    String toString(){
		login
    }

}
